import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2022-09-27
 * Time: 23:23
 */
class MinStack {

    Stack<Integer> stack;
    Stack<Integer> minStack;
    public MinStack() {
        stack=new Stack<>();
        minStack=new Stack<>();
    }

    public void push(int val) {
        stack.push(val);

        if(minStack.isEmpty()){
            minStack.push(val);
        }else{
            //注意有==以防出现多个最小值
            if(val<=minStack.peek()){
                minStack.push(val);
            }
        }
    }

    public void pop() {
        int val=stack.pop();
        //注意当pop中的值与最小值相同时minStack也要pop
        if(val==minStack.peek()){
            minStack.pop();
        }
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return minStack.peek();
    }
}